<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
    <head>
        <title>KAKA</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1">
        <link href="http://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
        <script type='text/javascript' src='/public/js/jquery-3.1.1.min.js'></script>
        <script type="text/javascript" src='/public/js/jquery.validate.js'></script>
        <script type="text/javascript" src='/public/js/main/main.js'></script>
        <script>
            var _hmt = _hmt || [];
            (function () {
                var hm = document.createElement("script");
                hm.src = "//hm.baidu.com/hm.js?8d43b5b5d798921b66d689f7a792e6e2";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(hm, s);
            })();
        </script>
        <script type="text/javascript">
            document.domain = '<?php echo _DOMAIN_ALL_;?>';
        </script>
        <link rel="shortcut icon" type="image/ico" href="/favicon.ico">
    </head>
    <body style="background-color: #f4f4f4">
 
<link href="/public/css/main.css" rel="stylesheet">
<script type="text/javascript">
    $(document).ready(function () {
        $('._header').width($('.container').width());
    })
</script>
<div class="container" style="background-color: white">
    <div class='_main'>
        <div class="banner">
           <!--  <div class='_logo'>
                <a href='/'><img src="/public/images/kaka.png" class='logo_img'  alt='banner'/></a>
            </div> -->
            <a href='/'><img src="/public/images/banner.png" class='banner_img'  alt='banner'/></a>
        </div>
        <div class='_header'>
            <div style='padding-right: 5rem;padding-top:1px' id="welcome">
                <span class=''><a class='_a' href="/home/passport/login"><img src="/public/images/login.png" width='90px' ></a></span>
                <span class='_span'></span>
                <span class='_span'><a class='_a' href="/home/passport/register"><img src="/public/images/register.png" width='90px' ></a></span>
            </div>
            <div style='display:none;color:white' id="already_login">
                <span class='as'><a class='_a color1' href="javascript:void(0);"><b id="login_name"></b><?php if( $msg_num != 0 ){ ?> <a href="/home/message/message"><span class="_message"><?php echo $msg_num; ?></span></a> <?php }?></a> </span>
                <span class='_span as'><b>|</b></span>
                <span class='_span' style="width:7rem"><a class='_a color1' href="/home/passport/repassword"><b>修改密码</b></a></span>
                <span class='_span as'><b>|</b></span>
                <span class='_span'><a class='_a color1' href="/home/passport/logout"><b>退出</b></a></span>
            </div>
        </div>
        <div class="_menu" id='_menu'>
            <div class='_menu_in'>
                <!-- <span class='_menu_b'>
                    <a class='wa' href="/home/company">公司</a>
                </span> -->
                <span class="<?php if(strstr(strtolower($_SERVER['REQUEST_URI']),'/home/store')){?>_menu_b_2<?php }else{?>_menu_b<?php }?>">
                    <a class="<?php if(strstr(strtolower($_SERVER['REQUEST_URI']),'/home/store')){?>_a<?php }else{?>wa<?php }?>" href='/home/store'>店铺</a>
                </span>
                <span class="<?php if(strstr(strtolower($_SERVER['REQUEST_URI']),'home/barber')){?>_menu_b_2<?php }else{?>_menu_b<?php }?>">
                    <a class="<?php if(strstr(strtolower($_SERVER['REQUEST_URI']),'/home/barber')){?>_a<?php }else{?>wa<?php }?>" href='/home/barber'>成员</a>
                </span>
                <span class="<?php if(strstr(strtolower($_SERVER['REQUEST_URI']),'/home/action')){?>_menu_b_2<?php }else{?>_menu_b<?php }?>">
                    <a class="<?php if(strstr(strtolower($_SERVER['REQUEST_URI']),'/home/action')){?>_a<?php }else{?>wa<?php }?>" href='/home/action'>活动</a>
                </span>
                <span class="<?php if(strstr(strtolower($_SERVER['REQUEST_URI']),'/home/order')){?>_menu_b_2<?php }else{?>_menu_b<?php }?>">
                    <a class="<?php if(strstr(strtolower($_SERVER['REQUEST_URI']),'/home/order')){?>_a<?php }else{?>wa<?php }?>" href='/home/order'>订单</a>
                </span>
                <span class="<?php if(strstr(strtolower($_SERVER['REQUEST_URI']),'/home/coupon')){?>_menu_b_2<?php }else{?>_menu_b<?php }?>">
                    <a class="<?php if(strstr(strtolower($_SERVER['REQUEST_URI']),'/home/coupon')){?>_a<?php }else{?>wa<?php }?>" href='/home/coupon'>优惠劵</a>
                </span>
                <span class="<?php if(strstr(strtolower($_SERVER['REQUEST_URI']),'/home/goods')){?>_menu_b_2<?php }else{?>_menu_b<?php }?>">
                    <a class="<?php if(strstr(strtolower($_SERVER['REQUEST_URI']),'/home/goods')){?>_a<?php }else{?>wa<?php }?>" href='/home/goods'>商品</a>
                </span>
            </div>
        </div>
        <div class='_line'></div>
 
<div class="_contro">
    <a href="/home/coupon/" class="_a"><font style='font-size:1.5rem'>返回列表页</font></a>
</div>
<div class='_cut'></div>
<div class='content'>   
    <form action="/home/coupon/submit" method="post" id='form'>
        <div class='form-group row'>
            <label for="exampleInputName2" class="_label">所属门店:</label>
            <select name='store'>
                <option>请选择门店</option>
                <?php  foreach($_store as $v){?>
                <option value='<?php echo $v['id'];?>' <?php if($v['id']==$barber['store_id'] || (int)$coupon['store_id']==$v['id'] ){echo "selected='selected'";}?>><?php echo $v['name'];?></option>
                <?php } ?>
            </select>
        </div>
        <div class='form-group row'>
            <label for="exampleInputName2" class="_label">优惠劵名称:</label>
            <input type="text" class="row _minput" name='name' id='name' placeholder="" value="<?php echo $coupon['name'] ?>" style="width:15rem;"/>
        </div>         
        <div class="form-group row">
            <label for="exampleInputName2" class="_label" >优惠劵类型:</label>
            <select name="type_name" class='_select' id='type_name'>
                <option value="折扣券" <?php if($coupon['type_name']=="折扣券"){echo "selected='selected'";}?>>折扣券</option>
                <option value="现金券" <?php if($coupon['type_name']=="现金券"){echo "selected='selected'";}?>>现金券</option>
                <option value="体验券" <?php if($coupon['type_name']=="体验券"){echo "selected='selected'";}?>>体验券</option> 
            </select>
        </div> 
        <div class='form-group row'>
            <label for="exampleInputName2" class="_label">优惠劵折扣:</label>
            <input type="text" name="content" id="content" placeholder="折扣数" value="<?php echo $coupon['content'] ?>" style="width:5rem;"><span id='yuan'>折</span>&nbsp;&nbsp;
            店内消费满<input type='text' name='condition' id='condition' placeholder='可不填' value='<?php echo $coupon['condition']?>' style="width:5rem;">元使用
        </div>
        <div class='form-group row'>
            <label for="exampleInputName2" class="_label">优惠劵数量:</label>
            <input type="text" class="row _minput" name='num' placeholder=""  value="<?php if($coupon['num']){echo $coupon['num'];} ?>" style="width:15rem;"/>
            <span class="_prompt">请填写优惠劵数量小于100张</span>
        </div>
        <!-- <div class="form-group row">
                    <label for="exampleInputName2" class="_label">优惠劵样式:</label>
                    <select name="style" class='_select'>
                        <option value="1" <?php if($coupon['style']==1){echo "selected='selected'";}?>>样式1</option>
                    </select>
        </div> -->
        <input type='hidden' name='style' value="1" >
        <?php if($coupon['start_time']!=''){ ?>
        <div id='model'>
            
            <div class='form-group row'>
                <label for="exampleInputName2" class="_label">开始日期:</label>
                <input type="text" class="row _minput" name='start_time' placeholder="" value="<?php echo date('Y-m-d',$coupon['start_time']) ?>" onfocus="WdatePicker();" onblur=""/>
            </div>
            <div class='form-group row'>
                <label for="exampleInputName2" class="_label">结束日期:</label>
                <input type="text" class="row _minput" name='end_date' placeholder="" value="<?php echo date('Y-m-d',$coupon['end_date']) ?>" onfocus="WdatePicker();" onblur=""/>
            </div>
            <div class='form-group row'>
                <label for="exampleInputName2" class="_label">使用截止时间:</label>              
                <input type="text" class="row _minput" name='end_time' placeholder="" value="<?php echo date('Y-m-d',$coupon['end_time']) ?>" onfocus="WdatePicker();" onblur=""/>
            </div>
            
        </div>
        <?php }else{?>
        <div id='model'>    
            <div class='form-group row'>
                <label for="exampleInputName2" class="_label">开始日期:</label>
                <input type="text" class="row _minput" name='start_time' placeholder="" value="" onfocus="WdatePicker();" onblur=""/>
            </div>
            <div class='form-group row'>
                <label for="exampleInputName2" class="_label">结束日期:</label>
                <input type="text" class="row _minput" name='end_date' placeholder="" value="" onfocus="WdatePicker();" onblur=""/>
            </div>
            <div class='form-group row'>
                <label for="exampleInputName2" class="_label">使用截止时间:</label>              
                <input type="text" class="row _minput" name='end_time' placeholder="" value="" onfocus="WdatePicker();" onblur=""/>
            </div>
            
        </div>
        <?php }?>
        <div class='form-group row'>
            <label for="exampleInputName2" class="_label">优惠劵说明:</label>
        </div>
        <div class='form-group row'>
            <textarea style="margin-left:5rem;width:40rem;" name='intro' id="_intro" class="_textarea" placeholder="可不写"><?php echo $coupon['intro']; ?></textarea>

        </div>
        <?php if(!$coupon || $coupon['status']==0){?>
        <div class="form-group _submit_div row">
            <input name='coupon_id' type='hidden'  value="<?php echo $coupon['id']?>">
            <input name='create' id='create' class='_button' type="button" value="预览" onclick="_submit(2);"/>
            <input name='caogao' id='caogao' class='_button' type="submit" value="保存草稿" onsubmit="return _submit(1);"/>
        </div>
        <?php } ?>
    </form>

</div>

<script type='text/javascript' src='/public/js/date/WdatePicker.js'></script>

<script type='text/javascript'>
                $(document).ready(function () {


                    $("#form").validate({
                        rules: {
                            store:{
                                required: true,
                                min:1
                            },
                            name: {
                                required: true,
                                rangelength: [0, 11],
                            },
                            num: {
                                required: true,
                                range: [-1, 100],
                            },
                            start_time: {
                                required: true,
                            },
                            end_time: {
                                required: true,
                            },
                            content: {
                                required: true,
                            }

                        },
                        messages: {
                            store:{
                                required: '请选择店铺',
                                min: '请选择店铺'
                            },
                            name: {
                                required: '请填写优惠劵名称',
                                rangelength: '请填写字数小于11个',
                            },
                            num: {
                                required: '请填写优惠劵数量',
                                range: '请填写数量小于100',
                            },
                            start_time: {
                                required: '请选择开始使用日期',
                            },
                            end_time: {
                                required: '请选择结束使用日期',
                            },
                            content: {
                                required: '请填写优惠劵折扣',
                            }
                        }
                    });
                });

                function _submit(type) {
                    if (type == 1) {
                        $('#create').remove();
                    } else {
                        $('#caogao').remove();
                    }
                    $('#form').submit();
                }

                $("#type_name").change(function () {
                    var num = '';
                    if ($("#type_name").val() == "现金券") {
                        num = 1;
                    } else if ($("#type_name").val() == "折扣券") {
                        num = 0;
                    } else {
                        num = 2;
                    }
                    $.ajax({
                        url: "/home/coupon/ajax?num=" + num,
                        async: true,
                        success: function (data) {
                            if (data == "false") {
                                return;
                            } else if (data == 1) {
                                $('#content').attr('placeholder', "金额");
                                $("#yuan").html('元');
                            } else if (data == 0) {
                                $('#content').attr('placeholder', "折扣数");
                                $("#yuan").html('折');
                            } else if (data == 2) {
                                $('#content').attr('placeholder', "金额");
                                $("#yuan").html('元');
                            }
                        }
                    });
                });
                if ($("#type_name").val() == "现金券") {
                    $('#content').attr('placeholder', "金额");
                    $("#yuan").html('元');
                } else if ($("#type_name").val() == "折扣券" || $("#type_name").val() == '') {
                    $('#content').attr('placeholder', "折扣数");
                    $("#yuan").html('折');
                } else {
                    $('#content').attr('placeholder', "项目名");
                    $("#yuan").html('');
                }



</script> 

</div>
<div class="_line"></div>
<div class="_footer">
    ©2015-<?php echo date('Y');?> All Rights Reserved ( 京ICP备15010043号 )
</div>
</div>
<div id='mask_layer' style="text-align: center;width:100%;height:100%;overflow:hidden;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#8E8E8E',endColorstr='##8E8E8E');
    background-color:rgba(255, 255, 255, 0.4);position:fixed; _position:absolute; top:0;left:0; z-index:5000;display:none ">
    <div style="padding-top: 20%"><h1><b>loading<span id="_loading"></span></b></h1></div>
</div>
    </body>
</html>